Cast Item To Module ?

Is it possible to make case:

Item item;

Module mod

if(type(item)==""Formal"){

mod = (Module) item

}

But does not work I only find solution like:

Item item;

Module mod

if(type(item)=="Module"){

     mod = read(f

}

 

Why this happens we know that runtime the type is Module, we have to be able to cast the object.


Dinio - Fri Dec 18 09:34:10 EST 2015

Re: Cast Item To Module ?
Mathias Mamsch - Fri Dec 18 10:40:43 EST 2015

The  "Module" type in DXL does not represent an Item. An Item is a Container, either a Folder/Project (contains Other Items), a "Formal Module" (contains module versions) or a "Link Module" (contains link module versions).

The "Module" DXL Type represents a loaded ModuleVersion (current or Baseline). Therefore you cannot cast an Item to a Module. You need to explicitly open the current version or a baseline of the item to retrieve a Module variable. Regards, Mathias

 

Edit: By the way - if the module is already opened, you can get the module handle from the Item

Item I 
...
if (type I == "Formal" || type I == "Link") {
    Module mod = module I   // if the module is open, you will get the handle here
    if (mod == null) mod = read(...)
}